﻿/*  Kiva.NET
 *  Copyright (c) 2009 Arun Kumar 
 *  middleforce@gmail.com
 */
namespace KivaLibrary
{
    public static class KivaConstants
    {
        public const string baseURL = "http://api.kivaws.org/v1/";
        public const string urlSuffix = ".xml";
    }
    public static class KivaURLFactory
    {
        public static string GetLenderURL(string uid)
        {
            return KivaConstants.baseURL + "lenders/" + uid + KivaConstants.urlSuffix;
        }
        public static string GetLenderLoansURL(string uid, int pageNumber)
        {
            return KivaConstants.baseURL + "lenders/" + uid + "/loans" + KivaConstants.urlSuffix + "?page=" + pageNumber.ToString(); ;
        }
        public static string GetAllPartnersURL(int pageNumber)
        {
            return KivaConstants.baseURL + "partners" + KivaConstants.urlSuffix + "?page=" + pageNumber.ToString();
        }
        public static string GetLoanURL(string id)
        {
            return KivaConstants.baseURL + "loans/" + id.ToString() + KivaConstants.urlSuffix;
        }
        public static string GetNewestLoansURL(int pageNumber)
        {
            return KivaConstants.baseURL + "loans/newest" + KivaConstants.urlSuffix + "?page=" + pageNumber.ToString();
        }
        public static string GetLoanLendersURL(string id, int pageNumber)
        {
            return KivaConstants.baseURL + "loans/" + id + "/lenders" + KivaConstants.urlSuffix + "?page=" + pageNumber.ToString(); ;
        }
        public static string GetLoansURL(string status, string gender, string sector, string region,
                     string countryCode, string partnerID, string query, int pageNumber)
        {
            string searchURL = "http://api.kivaws.org/v1/loans/search.xml?&page=" + pageNumber;
            if (status + "" != "")
            {
                searchURL += "&status=" + status;
            }
            if (gender + "" != "")
            {
                searchURL += "&gender=" + gender;
            }
            if (sector + "" != "")
            {
                searchURL += "&sector=" + sector;
            }
            if (region + "" != "")
            {
                searchURL += "&region=" + region;
            }
            if (countryCode + "" != "")
            {
                searchURL += "&countryCode=" + countryCode;
            }
            if (partnerID + "" != "")
            {
                searchURL += "&partnerID=" + partnerID;
            }
            if (query + "" != "")
            {
                searchURL += "&query=" + query;
            }
            return searchURL;
        }
    }
}
